package com.gtxc.kotlinmvvm

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.aleyn.mvvm.base.BaseViewModel
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.SPStaticUtils
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.gtxc.kotlinmvvm.config.Config
import com.gtxc.kotlinmvvm.network.request.LoinBean
import com.gtxc.kotlinmvvm.network.request.User
import com.gtxc.kotlinmvvm.ui.activity.HomeActivity
import com.gtxc.kotlinmvvm.utlis.BooleanObservableField
import com.gtxc.kotlinmvvm.utlis.JSONUtils
import com.gtxc.kotlinmvvm.utlis.StringObservableField
import com.mot.st.network.request.ApiNetWork

class LoginViewModel : BaseViewModel() {

    val editTextUsernameValue = MutableLiveData<String>()
    val editTextPasswordValue = MutableLiveData<String>()
    val magess = MutableLiveData<String>()
    val ok = MutableLiveData<Boolean>()
    init {

    }

    fun Login(loinBean: LoinBean) {
        launchUI {
            val result =     ApiNetWork.getInstance().postLogin(loinBean)
            ok.value=result.success
            if ( result.success){
                Log.i("dedreff5rg5g5", "Login: "+result.resultObj)
                SPUtils.getInstance().put(Config.HTTP_TOKEN_KET,result.resultObj.token)
                SPUtils.getInstance().put(Config.USER_ID,result.resultObj.User.id)

                ToastUtils.showShort("登录成功")
            }else{
//                Log.i("dedreff5rg5g5", "Login: "+result.token)
                ToastUtils.showShort("登录失败"+result.message)
                magess.value="登录失败"+result.message
            }
        }

    }
}